package lion.framework.core.json.anno;

import java.lang.annotation.Annotation;

import lion.dev.lang.MapJ;
import lion.framework.core.anno.AnnoProcessor;
import lion.framework.core.anno.AnnotationProcessorManager;
import lion.framework.core.anno.IAnnotationProcessor;
import lion.framework.core.bean.BeanFactory;
import lion.json.IJsonHandler;
import lion.json.Json;

@AnnoProcessor(JsonHandler.class)
public class JsonHandlerAnnoProcessor implements IAnnotationProcessor {

	@Override
	public void processe(MapJ ctx, Annotation anno) throws Exception {

		Class<?> clazz = ctx.getE(AnnotationProcessorManager.ANNO_CONTEXT_CLASS);
		if (IJsonHandler.class.isAssignableFrom(clazz)) { return; }

		JsonHandler jh = (JsonHandler) anno;

		Class<?> clazzM = jh.value();

		Json.registHandler(clazzM, (IJsonHandler) BeanFactory.create(clazz));
	}
}
